package com.jzy.bxb.app.scripts.http.user;

import com.jzy.bxb.app.server.AuthHttpHandler;
import com.jzy.bxb.core.handler.HandlerEntity;
import com.jzy.bxb.model.mongo.dao.UserDao;
import com.jzy.bxb.model.mongo.entity.Address;

/**
 * 编辑地址
 * http://127.0.0.1:8680/user/address/edit?sid=c6241261-1bff-461f-81a1-7a0bc5470319&fullAddr=chengdu&community=yongle&unitNo=1&&houseNo=101<br>
 * http://112.74.36.233:8680/user/address/edit?sid=06106c0a-6cfd-4202-9657-ef2bb8eb8ace&fullAddr=chengdu&community=yongle&unitNo=1&&houseNo=101<br>
 * <li>fullAddr 完整地址</li>
 * <li>city 城市</li>
 * <li>county 区县</li>
 * <li>community 小区</li>
 * <li>unitNo 单元号</li>
 * <li>houseNo 房间号</li>
 * 
 * 
 * @author JiangZhiYong
 * @date 2017-06-26 QQ:359135103
 */
@HandlerEntity(path = "/user/address/edit")
public class AddressEditHandler extends AuthHttpHandler {

	@Override
	public void run() {

		Address address = user.getAddress();
		if (address == null) {
			address = new Address();
			user.setAddress(address);
		}
		String fullAddr = getString("fullAddr");
		if (fullAddr != null) {
			address.setFullAddr(fullAddr);
		}
		
		String city = getString("city");
		if (city != null) {
			address.setCity(city);
		}
		
		String county = getString("county");
		if (county != null) {
			address.setCounty(county);
		}

		String community = getString("community");
		if (community != null) {
			address.setCommunity(community);
		}

		String unitNo = getString("unitNo");
		if (unitNo != null) {
			address.setUnitNo(unitNo);
		}

		String houseNo = getString("houseNo");
		if (houseNo != null) {
			address.setHouseNo(houseNo);
		}
		UserDao.saveUser(user);
		sendMsg(user.getAddress());
	}

}
